#ifndef LIBSI_H_
#define LIBSI_H_

	#include "xparameters.h"
	#include "xutil.h"
	#include <xhwicap.h>

	///////////////////////////////////////RAM/////////////////////////////////////////////////
	#define RAM_nTB						(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x000F0000)
	#define RAM_TESTBENCH				(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00100000)
	#define RAM_GOLDEN					(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00200000)
	#define RAM_ERRORES					(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00300000)
	#define RAM_BITSTREAM_ORIGINAL   	(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00400000)
	#define RAM_BITSTREAM_MODIFICADO 	(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00000800)
	#define RAM_BITSTREAM_RESTORER 		(XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00008000)
	#define RAM_FDRI_BLOCKS             (XPAR_DDR2_SDRAM_MPMC_BASEADDR + 0x00080000)

	static volatile unsigned int * pto_ram_nTB = (volatile unsigned int *) RAM_nTB;
	static volatile unsigned int * pto_ram_testbench = (volatile unsigned int *) RAM_TESTBENCH;
	static volatile unsigned int * pto_ram_golden = (volatile unsigned int *) RAM_GOLDEN;
	static volatile unsigned int * pto_ram_errores = (volatile unsigned int *) RAM_ERRORES;
	static volatile unsigned int * pto_ram_bitOriginal = (volatile unsigned int *) RAM_BITSTREAM_ORIGINAL;
	static volatile unsigned int * pto_ram_bitModificado = (volatile unsigned int *) RAM_BITSTREAM_MODIFICADO;
	static volatile unsigned int * pto_ram_bitRestorer = (volatile unsigned int *) RAM_BITSTREAM_RESTORER;
	static volatile unsigned int * pto_ram_FDRI_blocks = (volatile unsigned int *) RAM_FDRI_BLOCKS;



	///////////////////////////////////////UART////////////////////////////////////////////////
	#define UART_SALIDA					XPAR_ADAPTADOR_UART_0_BASEADDR
	#define UART_SALIDA_OCUPADA			(XPAR_ADAPTADOR_UART_0_BASEADDR + 4)
	#define UART_ENTRADA				(XPAR_ADAPTADOR_UART_0_BASEADDR + 8)
	#define UART_ENTRADA_LISTA			(XPAR_ADAPTADOR_UART_0_BASEADDR + 12)

	static volatile unsigned int * pto_uart_salida =(volatile unsigned int *) UART_SALIDA;
	static volatile unsigned int * pto_uart_salida_ocupada = (volatile unsigned int *) UART_SALIDA_OCUPADA;
	static volatile unsigned int * pto_uart_entrada =(volatile unsigned int *) UART_ENTRADA;
	static volatile unsigned int * pto_uart_entrada_lista =(volatile unsigned int *) UART_ENTRADA_LISTA;

	void enviarDato(volatile unsigned int *dir);
	void recibirDato(volatile unsigned int *dir);
	void enviarEntradaTB(volatile unsigned int *dir);
	void recibirEntradaTB(volatile unsigned int *dir);
	void inicializarUart();
	


	////////////////////////////////ADAPTADOR_CIRCUITO//////////////////////////////////////////
	static volatile unsigned int * pto_adaptador_circuito =(volatile unsigned int *)XPAR_ADAPTADOR_CIRCUITO_0_BASEADDR;
	static volatile unsigned int * pto_circuito_entrada;
	static volatile unsigned int * pto_circuito_salida;

	void inicializarAdaptadorCircuito(int num);
	void escribirEntradaTB(unsigned int *dir);
	void leerEntradaTB(unsigned int *dir);


	///////////////////////////////////////ICAP////////////////////////////////////////////////
	#define ICAP						(XPAR_HWICAP_0_BASEADDR)

	static volatile unsigned int * pto_icap =(volatile unsigned int *) ICAP;

	int inicializarIcap(XHwIcap * icap);
	int programar_icap(XHwIcap * icap,Xuint32 *data, Xuint32 tamano);



#endif /*LIBSI_H_*/
